package activity

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/activityinfo"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/rpc"
	"github.com/zeromicro/go-zero/core/logc"
	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateActivityLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 修改
func NewUpdateActivityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateActivityLogic {
	return &UpdateActivityLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateActivityLogic) UpdateActivity(req *types.UpdateActivityInfoReq) (resp *types.Empty, err error) {
	if req.Id == 0 {
		return nil, code.ParamsInvalid
	}

	u, err := l.svcCtx.SettingService.Activity.UpdateActivity(l.ctx, &activityinfo.UpdateActivityInfoReq{
		Id: req.Id,
		Data: &activityinfo.AddActivityInfoReq{
			MerchantId:  1,
			Title:       req.Data.Title,
			JumpType:    req.Data.JumpType,
			Status:      rpc.StatusType(req.Data.Status),
			Cover:       req.Data.Cover,
			ActivityPic: req.Data.ActivityPic,
			Sort:        req.Data.Sort,
		},
	})

	if err != nil {
		logc.Error(l.ctx, "UpdateActivity err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}
	resp = &types.Empty{}
	return
}
